package us.icitap.commandcenter.ui.operator;

import java.util.List;
import com.vaadin.data.util.BeanItemContainer;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;

import us.icitap.commandcenter.CommandCenterUI;
import us.icitap.commandcenter.business.ejb.persistence.Call;
import us.icitap.commandcenter.ui.custom.CustColumnGenerator;
import us.icitap.commandcenter.ui.custom.CustTable;
import us.icitap.commandcenter.ui.shared.CallTable;

public class CallList extends CallTable{


	private  final BeanItemContainer<Call> beans = new BeanItemContainer<Call>(Call.class);
	
	public CallList() {
	
		super("Totali i telefonatave: ");
		this.addGeneratedColumn("relatedCallNr", CustColumnGenerator.relatedCallNumberColumnGenerator);
		
		this.setVisibleColumns(new Object[]{"relatedCallNr","caller", "address", "description", "callReason", "mainDispatcher", "forSupervisor", "recordDate"});
		this.setColumnHeaders(new String[]{"NR I TEL", "TELEFONUESI", "ADRESA", "PERSHKRIMI", "ARSYEJA E TELEFONATES", "ZONA E MBULIMIT", "PER SUPERVIZORIN", "DT. REGJ."});
		this.addGeneratedColumn("caller", CustColumnGenerator.callerColumnGenerator);
		this.addGeneratedColumn("callReason", CustColumnGenerator.callReasonColumnGenerator);
		this.addGeneratedColumn("mainDispatcher", CustColumnGenerator.dispatcherColumnGenerator);
		this.addGeneratedColumn("forSupervisor", CustColumnGenerator.yesNoColumnGenerator);
		this.setPageLength(20);
		this.setWidth("950px");
		this.setColumnWidth("relatedCallNr", 30);
		this.setColumnWidth("callReason", 100);
		this.setColumnWidth("forSupervisor", 30);
		this.setColumnWidth("address", 200);
		this.setColumnWidth("description", 200);
	
		this.setSelectable(true);
		this.setImmediate(true);
		this.addValueChangeListener(new ValueChangeListener() {
			
			public void valueChange(ValueChangeEvent event) {
				if(event.getProperty() == null) return;
				if(event.getProperty().getValue() == null) return;
				Call call = (Call)event.getProperty().getValue();
				
				
				Window w = new Window("Te dhenat e telefonates");
				w.center();
				w.setModal(true);
				w.setResizable(false);
				VerticalLayout v = new VerticalLayout();
				v.addComponent(new Label(call.getToolTip(), ContentMode.HTML));
				w.setContent(v);
				
				CommandCenterUI.getCurrent().addWindow(w);
				
				
				
			}

			@Override
			public void valueChange(
					com.vaadin.data.Property.ValueChangeEvent event) {
				// TODO Auto-generated method stub
				
			}

			
		});

		this.updateTable();
	}

	
}
